package core;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import persistence.DataPersistor;

import java.io.IOException;
import java.util.List;
import java.util.ArrayList;

public class ITextPDFBarcodePrinterTest {
	private static List<Item> itemsToPrint;
	private static ITextPDFBarcodePrinter printer;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		DataPersistor.instance().init("-serial");
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		ProductFacade.setInstance(null);
		ContainerFacade.setInstance(null);
		ItemFacade.setInstance(null);
		ProductManager.setInstance(null);
		ItemManager.setInstance(null);
		RootStorageUnit.setInstance(null);
		
		//file.delete();
	}

	@Before
	public void setUp() throws Exception {
		ContainerFacade.clearAllData();
		Container testSU = ContainerFacade.instance().addStorageUnit("TestSU");
		
		Product p1 = new Product(new Barcode("512345123451", BarcodeType.PRODUCT), "This", 
				new Amount(1F, UnitOfMeasurement.count), 1, 1);
		Product p2 = new Product(new Barcode("512345123452", BarcodeType.PRODUCT), "test", 
				new Amount(1F, UnitOfMeasurement.count), 1, 1);
		Product p3 = new Product(new Barcode("512345123453", BarcodeType.PRODUCT), "worked!",
				new Amount(1F, UnitOfMeasurement.count), 0, 1);
		
		ProductFacade.instance().createProduct(p1, testSU);
		ProductFacade.instance().createProduct(p2, testSU);
		ProductFacade.instance().createProduct(p3, testSU);
		
		Item i1 = ItemFacade.instance().addItem(p1, testSU);
		Item i2 = ItemFacade.instance().addItem(p2, testSU);
		Item i3 = ItemFacade.instance().addItem(p3, testSU);
		
		itemsToPrint = new ArrayList<Item>();
		itemsToPrint.add(i1);
		itemsToPrint.add(i2);
		itemsToPrint.add(i3);
		
		itemsToPrint.add(i1);
		itemsToPrint.add(i2);
		itemsToPrint.add(i3);
		itemsToPrint.add(i1);
		itemsToPrint.add(i2);
		itemsToPrint.add(i3);
		
		
		printer = new ITextPDFBarcodePrinter();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testPrintBarcodes() {
		try {
			printer.printBarcodes(itemsToPrint);
		} catch (IOException e) {
			e.printStackTrace();
			fail("IOException");
		}
	}

}
